home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP11 / POPFONT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  1.7 KB  |  60 lines

  1. /*------------------------------------------
  2.    POPFONT.C -- Popup Editor Font Functions
  3.   ------------------------------------------*/
  4.  
  5. #include <windows.h>
  6. #include <commdlg.h>
  7.  
  8. static LOGFONT logfont ;
  9. static HFONT   hFont ;
  10.  
  11. BOOL PopFontChooseFont (HWND hwnd)
  12.      {
  13.      CHOOSEFONT cf ;
  14.  
  15.      cf.lStructSize      = sizeof (CHOOSEFONT) ;
  16.      cf.hwndOwner        = hwnd ;
  17.      cf.hDC              = NULL ;
  18.      cf.lpLogFont        = &logfont ;
  19.      cf.iPointSize       = 0 ;
  20.      cf.Flags            = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS
  21.                                                   | CF_EFFECTS ;
  22.      cf.rgbColors        = 0L ;
  23.      cf.lCustData        = 0L ;
  24.      cf.lpfnHook         = NULL ;
  25.      cf.lpTemplateName   = NULL ;
  26.      cf.hInstance        = NULL ;
  27.      cf.lpszStyle        = NULL ;
  28.      cf.nFontType        = 0 ;               // Returned from ChooseFont
  29.      cf.nSizeMin         = 0 ;
  30.      cf.nSizeMax         = 0 ;
  31.  
  32.      return ChooseFont (&cf) ;
  33.      }
  34.  
  35. void PopFontInitialize (HWND hwndEdit)
  36.      {
  37.      GetObject (GetStockObject (SYSTEM_FONT), sizeof (LOGFONT),
  38.                                               (PSTR) &logfont) ;
  39.      hFont = CreateFontIndirect (&logfont) ;
  40.      SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFont, 0) ;
  41.      }
  42.  
  43. void PopFontSetFont (HWND hwndEdit)
  44.      {
  45.      HFONT hFontNew ;
  46.      RECT  rect ;
  47.  
  48.      hFontNew = CreateFontIndirect (&logfont) ;
  49.      SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFontNew, 0) ;
  50.      DeleteObject (hFont) ;
  51.      hFont = hFontNew ;
  52.      GetClientRect (hwndEdit, &rect) ;
  53.      InvalidateRect (hwndEdit, &rect, TRUE) ;
  54.      }
  55.  
  56. void PopFontDeinitialize (void)
  57.      {
  58.      DeleteObject (hFont) ;
  59.      }
  60.